/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thread;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JLabel;

/**
 *
 * @author PyyPyLyn
 */
public class ProcessDownLoadRequest_Thread extends Thread{
    
    DatagramSocket ld_Socket;
    JLabel label;
    DatagramSocket upload_Socket;
    
    int dest_Port;
    ArrayList<Thread> List_Thread;

    public ProcessDownLoadRequest_Thread(JLabel lb) {
        try
        {
            ld_Socket = new DatagramSocket(4448);
            List_Thread = new ArrayList<Thread>();
            label = lb;
        }
        catch (Exception ex)
        {
            
        }
    }

    public void run() 
    {           
        byte[] data = new byte[1024];
        DatagramPacket request_Pck = new DatagramPacket(data, data.length);
        
        try
        {                        
            while(true)
            {
                ld_Socket.receive(request_Pck);
                data = request_Pck.getData();
                if(List_Thread.size() >= 20)
                {
                    int a =10;
                }                
                else
                {                   
                    label.setText("Da nhan goi tin download");
                    Upload_Thread ult = new Upload_Thread(request_Pck);
                    ult.start();                    
                    List_Thread.add(ult);
                }
                

            }
        }
        catch (Exception ex)
        {
            int a = 10;
        }
    }
    
    
    
}
